﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CubicFWNet.Data.Models;
using CubicFWNet.Data.ViewModal;

namespace CubicFWNet.Data.SystemManager
{
    public class InventoryChangeRepository : RepositoryBase<InventoryChange>
    {
        public IEnumerable<InventoryChangeView> GetList(string name, DateTime start, DateTime end)
        {
            var result = from inv in dbcontext.InventoryChanges
                         join pro in dbcontext.Products
                         on inv.ProductId equals pro.Id
                         //into proEmp
                         //from pro in proEmp.DefaultIfEmpty()
                         join s in dbcontext.Storage
                         on inv.InStorageId equals s.Id
                         where name == "" && pro.Name.Contains(name) && inv.CreateTime >= start && inv.CreateTime < end
                         select new InventoryChangeView
                         {
                             Id = inv.Id,
                             ProductId = inv.ProductId,
                             Amount = inv.Amount,
                             ConfirmTime = inv.ConfirmTime,
                             ConfirmId = inv.ConfirmId,
                             Confirm = inv.Confirm,
                             CreateTime = inv.CreateTime,
                             CreatorID = inv.CreatorID,
                             Memo = inv.Memo,
                             ProductName = pro.Name,
                             InStorageName = s.Name,
                             OutStorageId = inv.OutStorageId,
                             //Type = pro.Type,
                             Format = pro.Format,
                             SizeLenth = pro.SizeLenth,
                             SizeWidth = pro.SizeWidth,
                             Unit = pro.Unit,
                         };
            return result;
        }
    }
}
